Skip to content

op-devstack,op-service: context-logging, better test contexts, and log filters#16098

Merged
protolambda merged 2 commits intodevelopfrom
sysgo-ctx-logging
May 23, 2025
Merged

op-devstack,op-service: context-logging, better test contexts, and log filters#16098
protolambda merged 2 commits intodevelopfrom
sysgo-ctx-logging

Conversation

@protolambda
Copy link
Copy Markdown
Contributor

@protolambda protolambda commented May 23, 2025

Description

This depends on op-geth PR - ethereum-optimism/op-geth#611

Do not merge this monorepo PR until we update the go.mod to point to the squash-merge commit once ready. Done.

The lack of context info and log-filters per service was making debugging this week terrible, so I made changes so we can productively debug again, with configurable logging and all the annotated context at all times.

Features

Context-logging

Support for context-logging: attach a ctx to a log, and the log-handler can inspect it to adapt what happens, and track execution events.

And any log without context will get the default context from the logger, so test-scopes, services, etc. are always tagged by default.

This removes a log-wrapper hack we used to have in devstack. The logger is the native logger again now.

This also updates the testlogger to support the new extended logging interface.

Log handler composition

Log handler composition: allow for wrapping/unwrapping. So the different log handler utils we have all become compatible.

I updated the existing handler utils (the dynamic log level handler, the trace handler, and the log-capturer) to support this.

Log filtering

Efficient log filtering, at the slog.Handler.Enabled level where it's intended to be filtered.

Based on log context the calls can now be filtered, or adjusted in other ways. E.g. escalating the log-level of something that you're particularly interested in for the purposes of a test.

devtest context wrapping

To make contexts useful, we need to annotate them. The devtest.T and devtest.P now have a WithCtx to wrap with those annotations.

devtest test-scope context key

Test-scopes are tracked with a context key. See devtest.TestScope and devtest.AddTestScope.

devstack shim contexts

Each shim, and by extension each DSL object around it, now has context annotations. Like service-kind and chain ID.
More annotations can be added later.

devstack logging presets

presets.WithLogFiltersReset / presets.WithLogFilters / presets.WithPkgLogFilters / presets.WithTestLogFilters allow for log-filters to be applied.

These are devstack options; they can be applied globally to the package, to adjust the log level of all shared services, and set up the default log filters for individual test scopes.

		// Logging can be adjusted with filters globally
		presets.WithLogFilters(
			stack.KindLogFilter(stack.L2ProposerKind, logfilter.Mute()),
			stack.KindLogFilter(stack.L2BatcherKind, logfilter.Minimum(log.LevelError)),
			stack.KindLogFilter(stack.L2CLNodeKind, logfilter.Add(3)),
		),
		// E.g. elevate the logs of your test interactions, while keeping background resource logs quiet
		presets.WithTestLogFilters(logfilter.Add(4)),

Tests

  • Added unit tests for the new op-service components
  • Updated example test to show log-filter usage in devstack

Additional context

Metadata

@protolambda protolambda added M-do-not-merge Meta: Do not merge A-devnet-sdk Area: devnet-sdk labels May 23, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented May 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 58.39%. Comparing base (8145253) to head (52bb2e3).
Report is 2 commits behind head on develop.

❗ There is a different number of reports uploaded between BASE (8145253) and HEAD (52bb2e3). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (8145253) HEAD (52bb2e3)
cannon-go-tests-64 3 1
contracts-bedrock-tests 2 0
Additional details and impacted files
@@             Coverage Diff              @@
##           develop   #16098       +/-   ##
============================================
- Coverage    82.34%   58.39%   -23.95%     
============================================
  Files          161       63       -98     
  Lines         8812     4927     -3885     
============================================
- Hits          7256     2877     -4379     
- Misses        1416     1905      +489     
- Partials       140      145        +5     
Flag Coverage Δ
cannon-go-tests-64 65.37% <ø> (-1.96%) ⬇️
contracts-bedrock-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

see 122 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@protolambda protolambda removed the M-do-not-merge Meta: Do not merge label May 23, 2025
@protolambda protolambda marked this pull request as ready for review May 23, 2025 13:47
@protolambda protolambda requested review from a team May 23, 2025 13:47
@protolambda
Copy link
Copy Markdown
Contributor Author

protolambda commented May 23, 2025

I'll rebase this PR once #16050 is merged. There's a new log env variable that we'd like to be compatible. Probably best applied as a default preset option in this new log-level setting.

Edit: done, ready for review.

@teddyknox teddyknox self-requested a review May 23, 2025 17:06
Comment thread op-devstack/example/init_test.go
Comment thread op-devstack/sysgo/l2_challenger.go Outdated
Copy link
Copy Markdown
Contributor

@teddyknox teddyknox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@protolambda protolambda enabled auto-merge May 23, 2025 19:45
@protolambda protolambda added this pull request to the merge queue May 23, 2025
Merged via the queue into develop with commit f61fbd4 May 23, 2025
59 checks passed
@protolambda protolambda deleted the sysgo-ctx-logging branch May 23, 2025 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-devnet-sdk Area: devnet-sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants